package com.project.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.project.bean.PageBean;
import com.project.bean.StudentBean;
import com.project.dao.studentMapper;
import com.project.service.IStudentService;

@Service
public class studentServiceImpl implements IStudentService{ 
	@Autowired
	private studentMapper studao;  
	//学生充值	
	@Override
	public int addStudensMoney(int s_id, double money) {
		System.out.println("充值:"+money);
		StudentBean stu=studao.selectByPrimaryKey(s_id); 
		System.out.println("余额："+stu.getsMoney());
		money+=stu.getsMoney();
		stu.setsMoney(money);
		System.out.println("新的余额："+money);
		int num=studao.updateByPrimaryKey(stu);
		return num;
	}
	//添加学生详情
	@Override
	public int addInfo(StudentBean stu) {
		int num=studao.insert(stu);
		return num;
	}
	//分页显示所有学生
	@Override
	public PageBean findAllStudentToMap(int page, int size) {
		PageBean pageBean=new PageBean();
		Map<String,Integer> map=new HashMap<String,Integer>();
		map.put("page", (page-1)*size);
		map.put("size", size);
		List<StudentBean> list=studao.findStuByPage(map);
		int num=studao.findAllNumber();
		int totalpage=(num%size==0)?(num/size):(num/size+1);
		pageBean.setPage(page);
		pageBean.setSize(size);
		pageBean.setTotalNumber(num);	
		pageBean.setTotalPage(totalpage);
		pageBean.setList(list);
		return pageBean;
		
	}
	//查询学员详情
	@Override
	public StudentBean findById(int userid) {
		StudentBean stu=studao.selectByPrimaryKey(userid);
		return stu;
	}
	
	@Override
	public int updateStudentMessage(String sRealname, int sAge, int sGender, int id) {
		
		return studao.updateStudentMessage(sRealname, sAge, sGender, id);
	}

	@Override
	public int addStudentSUId(int suid) {
		
		return studao.addStudentSUId(suid);
	}

	@Override
	public List<StudentBean> findAllStu() {
		return studao.findAllStu();
	}
	@Override
	public StudentBean findStudentByUserId(int userId) {
		
		return studao.selectByUserId(userId);
	}
	
	

}
